﻿
@{
    Layout = "~/Views/Shared/_Layout_Admin.cshtml";
    bool isAdd = ViewBag.isAdd;
    ViewBag.Title = isAdd.IIF("添加", "编辑");
}
@using SyntacticSugar
@section js{
    <script src="~/_theme/ueditor/utf8-net/ueditor.config.js"></script>
    <script src="~/_theme/ueditor/utf8-net/ueditor.all.js"></script>
    <script>
        var ue = UE.getEditor('container');
        layui.define(['ejq', 'ajaxforms'], function (exports) {

            //变量
            var $ = layui.ejq;
            var url = $.action.url("DC_Submit", null, "DocContent", "AdminSite");
            var isAdd = $("#hideIsAdd").val() == "True";

            //元素
            var btnSave = $("#btnSave");
            var btnClose = $("#btnClose");
            var form = $("form");

            //事件
            btnSave.click(function () {
                form.ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function (msg) {
                        window.location.href = $.action.url("PageDCAdd", null, "DocContent", "AdminSite") + "?id=" + msg.ResultInfo.id;
                    }, error: function (msg) {
                    }
                });
            });
            btnClose.click(function () {
                window.close();
            })

            //如果是编辑填充表单
            if (!isAdd) {
                $.ajax({
                    url: $.action.url("DC_Single", null, "DocContent", "AdminSite"),
                    data: { id: $.request.queryString().id },
                    cache: false,
                    success: function (msg) {
                        form.formFill({ data: msg.ResultInfo })
                        ue.setContent(msg.ResultInfo.Content);
                    }
                })
            }
        });
    </script>
}
@Html.Hidden("hideIsAdd", isAdd)
<table class="action-table" width="100%">
    <tr>
        <td></td>
        <td class="right">
            <div class="top-submit-button">
                <button id="btnSave" class="layui-btn">@(isAdd.IIF("保存", "保存修改"))</button>
                <button id="btnClose" class="layui-btn">关闭</button>
            </div>
        </td>
    </tr>
</table>
<form class="layui-form" action="" style="width:calc(100% - 120px)">
    @Html.Hidden("id")
    <div class="layui-form-item">
        <label class="layui-form-label">分类</label>
        <div class="layui-input-block">
            <label class="layui-form-label" style="width:300px; text-align:left">@Request["typeName"]</label>
            <input type="hidden" name="TypeId" value="@Request["typeId"]" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="Title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <!-- 加载编辑器的容器 -->
            <script id="container" name="Content" style="height:500px" type="text/plain">
            </script>
        </div>
    </div>

</form>
